Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Loop over each item in an array and call the given function on every element.
The array-each npm package provides a simple utility for iterating over arrays and executing a function for each element. It is designed to be lightweight and efficient, making it suitable for scenarios where you need to perform operations on each item in an array.
Basic Iteration
This feature allows you to iterate over each element in an array and execute a callback function. The callback receives the current value, the index, and the original array.
const each = require('array-each');
const array = [1, 2, 3, 4];
each(array, function(value, index, array) {
console.log('Value:', value, 'Index:', index);
});
Early Exit
This feature allows you to exit the iteration early by returning `false` from the callback function. This can be useful for performance optimization when you find the element you are looking for.
const each = require('array-each');
const array = [1, 2, 3, 4];
each(array, function(value, index, array) {
if (value === 3) return false; // Exit early
console.log('Value:', value, 'Index:', index);
});
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a `_.forEach` method that offers similar functionality to array-each but with additional features and support for objects as well as arrays.
The async package provides higher-order functions and common patterns for asynchronous code. It includes an `async.each` method that allows for asynchronous iteration over arrays, which is useful for handling I/O-bound operations.
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It includes an `_.each` method that works similarly to array-each but also supports objects.
Loop over each item in an array and call the given function on every element.
npm i array-each --save
var each = require('array-each');
var result = [];
each(['a', 'b', 'c'], function (ele) {
result.push(ele + ele);
});
console.log(result);
//=> ['aa', 'bb', 'cc']
Return false
to "break" early:
var result = [];
each(['a', 'b', 'c'], function (ele) {
if (ele === 'b') return false;
result.push(ele + ele);
});
console.log(result);
//=> ['aa']
Loop over each item in an array and call the given function on every element.
Params
array
{Array}fn
{Function}thisArg
{Object}: Optionally pass a thisArg
to be used as the context in which to call the function.returns
{Array}Example
each(['a', 'b', 'c'], function (ele) {
return ele + ele;
});
//=> ['aa', 'bb', 'cc']
each(['a', 'b', 'c'], function (ele, i) {
return i + ele;
});
//=> ['0a', '1b', '2c']
Install dev dependencies:
npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on April 28, 2015.
FAQs
Loop over each item in an array and call the given function on every element.
The npm package array-each receives a total of 2,720,860 weekly downloads. As such, array-each popularity was classified as popular.
We found that array-each demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.